local ClassLuaUtils = class()
LuaUtils = ClassLuaUtils.new()

function ClassLuaUtils:SetLabel(Object, Content)
    local text = Object:GetComponent(typeof(Text))
    if text then
        text.text = Content
    else
        Debug.LogError("组件Text不存在")
    end
end

function ClassLuaUtils:SetTMLabel(Object, Content)
    local text = Object:GetComponent(typeof(TextMeshProUGUI))
    if text then
        text.text = Content
    else
        Debug.LogError("组件TextMeshProUGUI不存在")
    end
end

function ClassLuaUtils:GetTMInput(Object)
    local text = Object:GetComponent(typeof(TMP_InputField))
    if text then
        return text.text
    else
        Debug.LogError("组件TMP_InputField不存在")
    end
end

function ClassLuaUtils:IsNil(Object) --Nil == true
    if Object == nil then return true end

    return Object:Equals(nil)
end

function string.split(str, sep)
    local sep, fields = sep or "", {}
    local pattern = string.format("([^%s]+)", sep)
    str:gsub(pattern, function (c) fields[#fields + 1] = c end)
    return fields
end

function ClassLuaUtils:GetCellType(MsgCellType)
    local cellType = CellType.None
    if MsgCellType == CS_GS_pb.CellNull then
        cellType = CellType.None
    elseif MsgCellType == CS_GS_pb.CellBorder then
        cellType = CellType.Border
    elseif MsgCellType == CS_GS_pb.CellTrack then
        cellType = CellType.Track
    elseif MsgCellType == CS_GS_pb.CellManor then
        cellType = CellType.Manor
    end
    return cellType
end

function print_r ( t )  
    local print_r_cache={}
    local function sub_print_r(t,indent)
        if (print_r_cache[tostring(t)]) then
            print(indent.."*"..tostring(t))
        else
            print_r_cache[tostring(t)]=true
            if (type(t)=="table") then
                for pos,val in pairs(t) do
                    if (type(val)=="table") then
                        print(indent.."["..pos.."]:"..tostring(t).." {")
                        sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
                        print(indent..string.rep(" ",string.len(pos)+6).."}")
                    elseif (type(val)=="string") then
                        print(indent.."["..pos..']:"'..val..'"')
                    else
                        print(indent.."["..pos.."]:"..tostring(val))
                    end
                end
            else
                print(indent..tostring(t))
            end
        end
    end
    if (type(t)=="table") then
        print(tostring(t).." {")
        sub_print_r(t,"  ")
        print("}")
    else
        sub_print_r(t,"  ")
    end
    print()
end

table.print = print_r
